# Maintainer: @naveen521kk on Github, Naveen M K <naveen521kk@gmail.com>

_realname=gi-docgen
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2023.1
pkgrel=4
pkgdesc='Documentation tool for GObject-based libraries (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://gitlab.gnome.org/GNOME/gi-docgen"
license=('GPL3' 'spdx:Apache-2.0' 'CC0-1.0')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-python-jinja"
  "${MINGW_PACKAGE_PREFIX}-python-markdown"
  "${MINGW_PACKAGE_PREFIX}-python-markupsafe"
  "${MINGW_PACKAGE_PREFIX}-python-pygments"
  "${MINGW_PACKAGE_PREFIX}-python-typogrify"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-wheel"
  "${MINGW_PACKAGE_PREFIX}-python-sphinx"
  "${MINGW_PACKAGE_PREFIX}-python-sphinx_rtd_theme"
  "${MINGW_PACKAGE_PREFIX}-cc"
)
checkdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-flake8"
)
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('88adeda9cbf882569479701eada009afa5d94fa29d728653ec388c32035f7fa3')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname//_/-}-$pkgver" "python-build-${MSYSTEM}"
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
  make -C docs
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/flake8 --show-source
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSES/Apache-2.0.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/Apache-2.0.txt"
  install -Dm644 LICENSES/GPL-3.0-or-later.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/GPL-3.0-or-later.txt"

  mkdir -p "$pkgdir${MINGW_PREFIX}/share/doc/${_realname}"
  cp -r docs/_build/* "$pkgdir${MINGW_PREFIX}/share/doc/${_realname}"
}
